/**
 * Copyright (c) 2008 michiyasu wada
 * http://www.seyself.com/
 * 
 * Distributed under The MIT License.
 * [http://www.opensource.org/licenses/mit-license.php]
 */

package demo.objects 
{
import flash.display.Sprite;
import flash.events.Event;
import jp.progression.casts.CastButton;
import jp.progression.casts.CastSprite;
import flash.geom.Point;
import com.seyself.display.shapes.RectShape;
import flash.display.MovieClip;
import jp.progression.scenes.SceneId;

public class OverlayPageCast extends CastSprite
{
    //--------------------------------------------------------------------------
    //  Properties
    //--------------------------------------------------------------------------
    public var background:Sprite;
    public var innerWidth:Number = 520;
    public var innerHeight:Number = 560;
    
    public function get closeBtn():CastButton
    {
        return CastButton( getChildByName("_closeBtn") );
    }
    
    //--------------------------------------------------------------------------
    //  Constructor
    //--------------------------------------------------------------------------
    public function OverlayPageCast( previousId:SceneId ) 
    {
        if( closeBtn ){
            closeBtn.sceneId = previousId;
        }
    }
    
    //--------------------------------------------------------------------------
    //  Override Method
    //--------------------------------------------------------------------------
    override protected function _onCastAdded():void
    {
        background = new RectShape(0, 0, stage.stageWidth, stage.stageHeight, 0, 0.45);
        addChildAt( background, 0 );
        
        stage.addEventListener( "resize", resizeHandler );
        resizeHandler();
        
    }
    
    override protected function _onCastRemoved():void
    {
        stage.removeEventListener( "resize", resizeHandler );
    }
    
    
    //--------------------------------------------------------------------------
    //  Event Handler Method
    //--------------------------------------------------------------------------
    private function resizeHandler( event:Event=null ):void
    {
        background.width = stage.stageWidth;
        background.height = stage.stageHeight;
        var pos:Point = parent.globalToLocal( 
            new Point(
                (stage.stageWidth - innerWidth) / 2,
                (stage.stageHeight - innerHeight) / 2
            ));
        
        this.x = pos.x;
        this.y = pos.y;
        
        var bgPos:Point = this.globalToLocal( new Point() );
        background.x = bgPos.x;
        background.y = bgPos.y;
    }
    
}

}